﻿define(function (require, exports, module) {
    "require:nomunge,exports:nomunge,module:nomunge";
    var $ = require("jquery"),
        forimg = require("forimg")
    ;
    
    var init = function () {
        var $page = $("#page");

        if ($page.find(".hot_slideBox").length) {
            new forimg.slide({
                forImgBoxEle: '.hot_slideBox',
                forImgBoxListEle: ".hot_slideCon",
                forImgItemEle: ".hot_slideItem",
                interval: 6000,
                callback: function () {
                    var _this = this,
                        _box = this.forImgBox
                    ;

                    _box.hover(function () {
                        _box.find(".slide_btn").css("display", "block");
                    }, function () {
                        _box.find(".slide_btn").css("display", "none");
                    });

                    _box.on("click", ".pre_btn", function () {
                        _this.prev();
                        return false;
                    });
                    _box.on("click", ".next_btn", function () {
                        _this.next();
                        return false;
                    });

                    this.automatic(true);

                }
            });
        }
        
        bind();
    };

    var bind = function () {
        var $page = $("#page");

        /* 头部地区选择 */
        $page.find(".top_left_con").hover(function () {
            var $this = $(this);
            $this.find(".all_place").css("display", "block");
            $this.find(".tp").addClass("tp_bg");
            $this.find(".iconfont").empty().append("&#xf0004;");
        }, function () {
            var $this = $(this);
            $this.find(".all_place").css("display", "none");
            $this.find(".tp").removeClass("tp_bg");
            $this.find(".iconfont").empty().append("&#xf0005;");
        });

        /* 选择地区事件  */
        $page.on("click", ".p_name", function () {
            var $this = $(this),
                $box = $page.find(".tp span")    
            ;

            $box.text($this.text());

            $page.find(".p_name").removeClass("p_name_cur");
            $this.addClass("p_name_cur");

        });

        $page.on("click", ".fgn_item", function () {
            var $this = $(this),
                $box = $this.closest(".floor_goods"),
                _index = $box.find(".fgn_item").index($this)
            ;
            

            $box.find(".fgn_item").removeClass("fgn_item_cur")
            $this.addClass("fgn_item_cur");

            $box.find(".fgc_item").fadeOut(0);
            $box.find(".fgc_item").eq(_index).fadeIn(800);

            return false;
        });

    };

    init();


   
});
